# -*- coding: utf-8 -*-
"""
@Time ： 2022/7/28 20:44
@Auth ： Mr. William 1052949192
@Company ：特斯汀学院 @testingedu.com.cn
@Function ：第一个Web自动化脚本实战
笔记文档：https://www.yuque.com/docs/share/73a7c983-4fcd-4bcf-8838-de0675b1738a
项目路径：http://47.105.110.138:8000/index.php/Home/user/login.html
"""
from selenium import webdriver


# 创建浏览器对象
driver = webdriver.Chrome()

# 添加隐式等待
driver.implicitly_wait(5)

# 打开网站
driver.get('http://47.105.110.138:8000/index.php/Home/user/login.html')
# id定位
ele = driver.find_element('id','username')
# 操作元素
ele.send_keys('13800138006')

ele = driver.find_element('link text','淘宝网')
print(ele.get_attribute('outerHTML'))

ele = driver.find_element('partial link text','淘宝')
print(ele.get_attribute('outerHTML'))

# 输入密码
driver.find_element('xpath','//*[@id="password"]').send_keys('123456')
driver.find_element('xpath','//*[@id="verify_code"]').send_keys('111')
driver.find_element('xpath','//*[@id="loginform"]/div/div[6]/a').click()

# 获取昵称
nickname = driver.find_element('xpath','//a[@class="red userinfo"]').text
print(nickname)

# 搜索
driver.find_element('xpath','//*[@id="q"]').send_keys('手机')
driver.find_element('xpath','//*[@id="sourch_form"]/a').click()

# 点击第一个加入购物出
driver.find_element('link text','加入购物车').click()
driver.find_element('id','join_cart').click()
driver.find_element('xpath','//*[@id="layui-layer1"]/span/a').click()

# 结算
driver.find_element('xpath','//*[@id="hd-my-cart"]/a/div/span').click()
driver.find_element('link text','去结算').click()
driver.find_element('class name','checkout-submit').click()

